package cn.edu.bjtu.toychange.action;

import cn.edu.bjtu.toychange.entity.Requisition;
import cn.edu.bjtu.toychange.entity.Toy;
import cn.edu.bjtu.toychange.entity.User;
import cn.edu.bjtu.toychange.service.RequisitionService;
import cn.edu.bjtu.toychange.service.ToyService;
import cn.edu.bjtu.toychange.service.UserService;
import cn.edu.bjtu.toychange.service.impl.RequisitionServiceImpl;
import cn.edu.bjtu.toychange.service.impl.ToyServiceImpl;
import cn.edu.bjtu.toychange.service.impl.UserServiceImpl;

import com.opensymphony.xwork2.ActionSupport;

public class ToyRequisitionAction extends ActionSupport{
	
	private static final long serialVersionUID = 7034531712999825958L;
	private String UserA_ID;
	private String UserB_ID;
	private String ToyA_ID;
	private String ToyB_ID;
	private String Message;
	private RequisitionService requisitionService;
	private UserService userService;
	private ToyService toyService;
	
	public ToyRequisitionAction() {
		requisitionService = new RequisitionServiceImpl();
		userService = new UserServiceImpl();
		toyService = new ToyServiceImpl();
	}
	
	public String insert() {
		Requisition requisition = new Requisition();
		User User_A = userService.getUser(Integer.valueOf(UserA_ID));
		User User_B = userService.getUser(Integer.valueOf(UserB_ID));
		Toy Toy_A = toyService.getToy(Integer.valueOf(ToyA_ID));
		Toy Toy_B = toyService.getToy(Integer.valueOf(ToyB_ID));
		
		requisition.setUser1(User_A);
		requisition.setUser2(User_B);
		requisition.setToy1(Toy_A);
		requisition.setToy2(Toy_B);
		requisition.setR_reqMesgt(Message);
		
		boolean result = requisitionService.insertRequisition(requisition);
		
		if (result)
			return "true";
		else
			return "false";
	}
	
	/**
	 * structs2通过下面的方法控制数据的传递
	 * @return
	 */
	public String getUserA_ID() {
		return UserA_ID;
	}

	public void setUserA_ID(String userA_ID) {
		UserA_ID = userA_ID;
	}

	public String getUserB_ID() {
		return UserB_ID;
	}

	public void setUserB_ID(String userB_ID) {
		UserB_ID = userB_ID;
	}

	public String getToyA_ID() {
		return ToyA_ID;
	}

	public void setToyA_ID(String toyA_ID) {
		ToyA_ID = toyA_ID;
	}

	public String getToyB_ID() {
		return ToyB_ID;
	}

	public void setToyB_ID(String toyB_ID) {
		ToyB_ID = toyB_ID;
	}

	public String getMessage() {
		return Message;
	}

	public void setMessage(String message) {
		Message = message;
	}
	
	/**
	 * spring通过下面的方法注入service
	 * @return
	 */
	public RequisitionService getRequisitionService() {
		return requisitionService;
	}

	public void setRequisitionService(RequisitionService requisitionService) {
		this.requisitionService = requisitionService;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public ToyService getToyService() {
		return toyService;
	}

	public void setToyService(ToyService toyService) {
		this.toyService = toyService;
	}
}
